package com.kpx.app.view;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.kpx.app.R;
import com.kpx.app.activity.ActivityBindThird;
import com.kpx.app.activity.ActivityCertification;
import com.kpx.app.activity.ActivityCertificationPhoto;
import com.kpx.app.activity.ActivityUserInfo;
import com.kpx.app.activity.ActivityVideoCertification;
import com.kpx.app.bean.CertificationInfoBean;
import com.kpx.app.configs.Constants;
import com.kpx.app.utils.uiutils.IntentUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by congdy on 17/3/3.
 * 认证页面的认证条目
 */

public class ViewCertification extends LinearLayout {
    @BindView(R.id.img_tag)
    ImageView imgTag;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.txt_ismust)
    TextView txtIsmust;
    @BindView(R.id.txt_content)
    TextView txtContent;
    @BindView(R.id.txt_to_certification)
    TextView txtToCertification;
    @BindView(R.id.ll_to_certification)
    LinearLayout llToCertification;

    private int userCertificationstatus;
    public static final int STATUS_PASS = 0;//完成
    public static final int STATUS_WAITTING = 1;//审核中
    public static final int STATUS_TOCERTIFICATION = 2;//未完成
    public static final int STATUS_FAIL = 3;//审核失败
    private int position;
    private Context context;
    private boolean enable = true;
    private CertificationInfoBean b;

    public ViewCertification(Context context) {
        super(context);
        initView(context);
    }

    public ViewCertification(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public ViewCertification(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context) {
        View view = View.inflate(context, R.layout.item_certification, this);
        ButterKnife.bind(view);
        this.context = context;

    }

    public void setMention(int postion) {
        position = postion;
        switch (postion) {
            case 0:
                txtTitle.setText("注册成功");
                txtContent.setText("欢迎加入全民快拍秀大家庭！");
                txtIsmust.setVisibility(View.VISIBLE);
                break;
            case 1:
                txtTitle.setText("完善个人资料");
                txtContent.setText("您的个人资料将直接匹配任务，认真完善能更快接单哦~");
                txtIsmust.setVisibility(View.VISIBLE);
                break;
            case 2:
                txtTitle.setText("照片认证");
                txtContent.setText("男神女神们，快来上传你的美照吧！照片认证通过后即可抢单！");
                txtIsmust.setVisibility(View.VISIBLE);
                break;
            case 3:
                txtTitle.setText("视频认证");
                txtContent.setText("加入视频认证将会解锁更多权益，一大波订单即将来袭哦~");
                txtIsmust.setVisibility(View.GONE);
                break;
            case 4:
                txtTitle.setText("绑定第三方账号");
                txtContent.setText("绑定第三方平台账号后，将会帮助您接到更多对应平台商家的任务订单哦~");
                txtIsmust.setVisibility(View.GONE);
                break;
        }
    }

    public void setStatus(int userCertificationstatus, boolean enable) {
        this.enable = enable;
        this.userCertificationstatus = userCertificationstatus;
        switch (position) {
            case 0:
                setStatusTxtBg(userCertificationstatus, "", "","", enable);
                break;
            case 1:
                setStatusTxtBg(userCertificationstatus, "", "完善资料","", enable);
                break;
            case 2:
                setStatusTxtBg(userCertificationstatus, "审核中", "立即申请","认证失败", enable);
                break;
            case 3:
                setStatusTxtBg(userCertificationstatus, "审核中", "立即申请","认证失败", enable);
                break;
            case 4:
                setStatusTxtBg(userCertificationstatus, "继续绑定", "立即绑定","", enable);
                break;
        }
    }

    private void setStatusTxtBg(int userCertificationstatus, String s1, String s,String s2, boolean enable) {
        if (userCertificationstatus == STATUS_PASS) {
            imgTag.setBackgroundResource(R.drawable.certification_1);
        } else {
            switch (position) {
                case 1:
                    imgTag.setBackgroundResource(R.drawable.certification_2);
                    break;
                case 2:
                    imgTag.setBackgroundResource(R.drawable.certification_3);
                    break;
                case 3:
                    imgTag.setBackgroundResource(R.drawable.certification_4);
                    break;
                case 4:
                    imgTag.setBackgroundResource(R.drawable.certification_5);
                    break;
            }
        }
        switch (userCertificationstatus) {
            case STATUS_PASS:
                txtToCertification.setText("");
                txtToCertification.setBackgroundResource(R.drawable.certification_had_done);
                break;
            case STATUS_WAITTING:
                txtToCertification.setText(s1);
                txtToCertification.setBackgroundResource(R.drawable.certification_btn_enable);
                break;
            case STATUS_TOCERTIFICATION:
                txtToCertification.setText(s);
                txtToCertification.setBackgroundResource(enable ? R.drawable.certification_btn_enable : R.drawable.certification_btn_grey);
                break;
            case STATUS_FAIL:
                txtToCertification.setText(s2);
                txtToCertification.setBackgroundResource(enable ? R.drawable.certification_btn_enable : R.drawable.certification_btn_grey);
                break;
        }
    }

    @OnClick(R.id.ll_to_certification)
    public void onClick() {
        switch (userCertificationstatus) {
            case STATUS_PASS:
            case STATUS_FAIL:
            case STATUS_WAITTING:
                switch (position) {
                    case 2:
                        if (b != null&&b.getImsAuthenRecord()!=null) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable(Constants.KEY_CERINFO_BEAN,b);
                            IntentUtil.gotoActivity(context, ActivityCertificationPhoto.class,bundle);
                        }
                        break;
                    case 3:
                        if (b != null&&b.getVideosAuthenRecord()!=null) {
                            Bundle bundle = new Bundle();
                            bundle.putSerializable(Constants.KEY_CERINFO_BEAN,b);
                            IntentUtil.gotoActivity(context, ActivityVideoCertification.class,bundle);
                        }
                        break;
                    case 4:
                        IntentUtil.gotoActivity(context, ActivityBindThird.class);
                        break;
                }
                break;
            case STATUS_TOCERTIFICATION:
                if (!enable) {
                    return;
                }
                switch (position) {
                    case 0:
                        break;
                    case 1://完善信息
                        IntentUtil.gotoActivity(context, ActivityUserInfo.class);
                        break;
                    case 2:
                        IntentUtil.gotoActivity(context, ActivityCertificationPhoto.class);
                        break;
                    case 3:
                        IntentUtil.gotoActivity(context, ActivityVideoCertification.class);
                        break;
                    case 4:
                        IntentUtil.gotoActivity(context, ActivityBindThird.class);
                        break;
                }
                break;
        }
    }

    public void setCerInfo(CertificationInfoBean b) {
        this.b = b;
    }
}
